﻿package  {

	public class cell {
		public var hp:Number=0;
		public var hpc:Number=0;
		public var hpheal:Array=new Array(0.01,0.02,0.04,0.08,0.12,0.24,0.48,0.96);
		public var team:Number=0;
		public var attack:Number=1;
		public var attackrate:Array=new Array(240,120,60,30,15,7,4,2);
		public var attackcount:uint=0;
		public var attackspeed:Array=new Array(0.03,0.04,0.05,0.1,0.2,0.3,0.4,0.5);//transfer speed
		public var cellhpstage:Array=new Array(0,10,20,40,80,160,320,640);
		
		public function getstage():uint
		{
			var i:int;
			i=cellhpstage.length-1;
			for(;i>=0;i--)
			{
				//trace(i);
				if(hp>cellhpstage[i])
				{return i;}
			}
			return cellhpstage.length-1;
		}
		public function cell(vvc:Number) {
			// constructor code
			hpc=vvc;
		}
		public function glow()
		{
			var grr:uint=getstage();
			if(hp<hpc)hp+=hpheal[grr];
			if(hp>hpc)hp=hpc;
			attackcount++;
			//trace(attackcount,attackrate);
			attackcount=attackcount % attackrate[grr];
			//trace(attackcount,attackrate);
		}
		public function getpower():Boolean
		{
			if(hp>=attack)
			{
				hp-=attack;
				return true;
			}
			return false;
		}
		public function betransfer(force:Number,teams:Number):Boolean
		{
			if(team!=teams)force=-force;
			hp+=force;
			if(hp>hpc)hp=hpc;
			if(hp<0){hp=0;return true;}
			return false;
		}
	}
	
}
